# Copyright 2020 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_java//java:defs.bzl", "java_library")
load("//src/test/kotlin/io/bazel/kotlin:defs.bzl", "kt_rules_test")

java_library(
    name = "JdepsParserTestFixtures",
    testonly = True,
    srcs = glob(["testFixtures/*.java"]),
    deps = [
        ":JdepsParserTestFixtures2",
    ],
)

java_library(
    name = "JdepsParserTestFixtures2",
    testonly = True,
    srcs = glob(["testFixtures2/*.java"]),
)

kt_rules_test(
    name = "JdepsParserTest",
    srcs = ["jvm/JdepsParserTest.java"],
    deps = [
        "//src/main/kotlin/io/bazel/kotlin/builder/tasks",
    ],
)

kt_rules_test(
    name = "KotlinBuilderJvmAbiTest",
    srcs = ["jvm/KotlinBuilderJvmAbiTest.java"],
)

kt_rules_test(
    name = "KotlinBuilderJvmBasicTest",
    size = "large",
    srcs = ["jvm/KotlinBuilderJvmBasicTest.java"],
)

kt_rules_test(
    name = "KotlinBuilderJvmJdepsTest",
    size = "large",
    srcs = ["jvm/KotlinBuilderJvmJdepsTest.kt"],
    data = [
        ":JdepsParserTestFixtures",
        ":JdepsParserTestFixtures2",
    ],
)

kt_rules_test(
    name = "KotlinBuilderJvmStrictDepsTest",
    size = "large",
    srcs = ["jvm/KotlinBuilderJvmStrictDepsTest.kt"],
)

kt_rules_test(
    name = "KotlinBuilderJvmCoverageTest",
    size = "large",
    srcs = ["jvm/KotlinBuilderJvmCoverageTest.kt"],
)

kt_rules_test(
    name = "JdepsMergerTest",
    srcs = ["jvm/JdepsMergerTest.kt"],
    deps = [
        "//src/main/kotlin/io/bazel/kotlin/builder/utils/jars",
    ],
)

# Trick to get default files produced by jvm_import into data
filegroup(
    name = "auto_value",
    srcs = ["@kotlin_rules_maven//:com_google_auto_value_auto_value"],
)

filegroup(
    name = "auto_value_annotations",
    srcs = ["@kotlin_rules_maven//:com_google_auto_value_auto_value_annotations"],
)

kt_rules_test(
    name = "KotlinBuilderJvmKaptTest",
    srcs = ["jvm/KotlinBuilderJvmKaptTest.java"],
    data = [
        "auto_value",
        "auto_value_annotations",
    ],
)

kt_rules_test(
    name = "KotlinJvmTaskExecutorTest",
    srcs = ["jvm/KotlinJvmTaskExecutorTest.kt"],
    deps = [
        "//kotlin/compiler:kotlin-test",
        "//src/main/kotlin/io/bazel/kotlin/builder/tasks",
        "@kotlin_rules_maven//:junit_junit",
    ],
)

test_suite(
    name = "tasks_tests",
    tests = [
        ":JdepsMergerTest",
        ":JdepsParserTest",
        ":KotlinBuilderJvmAbiTest",
        ":KotlinBuilderJvmBasicTest",
        ":KotlinBuilderJvmCoverageTest",
        ":KotlinBuilderJvmJdepsTest",
        ":KotlinBuilderJvmKaptTest",
        ":KotlinBuilderJvmStrictDepsTest",
        ":KotlinJvmTaskExecutorTest",
    ],
)
